﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Lavka.Models;

namespace Lavka.Core
{
    public class ActionsHelper
    {
        public static List<Actions> GetActions(LavkaDbEntities context)
        {
            return context.Actions.ToList();
        }
        public static string GetActionPrice(Products product, LavkaDbEntities context)
        {
            if (context.Actions.Where(a => a.ProductId == product.ProductId).Count() > 0)
            {
                var productAction = context.Actions.Where(a => a.ProductId == product.ProductId).First();
                if (!string.IsNullOrEmpty(productAction.NewPrice.ToString()))
                {
                    return string.Format("{0:F}", productAction.NewPrice);
                }
            }
            return null;
        }
        public static List<Actions> GetActionProducts(LavkaDbEntities context)
        {
            return context.Actions.OrderBy(p => Guid.NewGuid()).Take(5).ToList();
        }
    }
}